//
//  EnChn.swift
//  Hyphenate-Demo-Swift
//
//  Created by JennyShi on 2018/4/26.
//  Copyright © 2018年 杜洁鹏. All rights reserved.
//

import UIKit
import os.log

class EnStatic: NSObject {
    
    //sourceViewControllerType
    static let fromCalendarWithoutSelectedDate = 1
    static let fromEventListToSeeFriendsReply = 2
    static let fromMatchFreeWithDateAndSlot = 3
    static let fromEventListToReplyFriend = 4
    static let fromNotificationToReplyFriendThenToMainPage = 5
    
    static let maxEnglishTitleLength = 50
    static let maxChineseTitleLength = 50

    //pickerViewForType
    static let calendarTypePicker = 0
    static let eventTypePicker = 1
    static let timesensibilityTypePicker = 2
    static let hourMinitePicker = 3

    //calendarTypeNumber
    static let calendarTypePublic = 0
    static let calendarTypePersonal = 1

    //matchOrFree
    static let getMatchSlots = 0
    static let getFreeSlot = 1

    static let enWords : [String : String] = [
        "Change profile" : "Change profile",
        "Desc" : "Description",
        "Avatar" : "Avatar",
        "avatar bigger than 2M" : "avatar bigger than 2M",
        "avatar not found" : "avatar not found",
        "avatar transfering，please wait" : "avatar transfering，please wait",
        "avatar uploading failed" : "avatar uploading failed",
        "Back" : "Back",
        "Calendar" : "Calendar",
        "CalendarTitle" : "MMM yyyy",
        "Calendar Type" : "Calendar Type",
        "Canada" : "Canada",
        "Cancel" : "Cancel",
        "China" : "China",
        "City" : "City",
        "code sent" : "code sent",
        "Country" : "Country",
        "Country Code" : "Country Code",
        "Date" : "Date",
        "Delete" : "Delete",
        "delete failed" : "delete failed",
        "Detail" : "Detail",
        "DoB" : "DoB",
        "Done" : "Done",
        "email" : "email",
        "End" : "End",
        "End Time" : "End Time",
        "end time later than friend's free time" : "end time later than friend's free time",
        "Event Type" : "Event Type",
        "Exit without inviting friend" : "Exit without inviting friend",
        "Exit without saving ?" : "Exit without saving ?",
        "female" : "female",
        "First Name" : "First Name",
        "Free" : "Free",
        "free" : "free",
        "Gender" : "Gender",
        "get data failed" : "get data failed",
        "get code" : "get code",
        "get code failed" : "get code failed",
        "get new code" : "get new code",
        "get phone code" : "get phone code",
        "get email code" : "get email code",
        "going" : "going",
        "HHmm" : "HH:mm",
        "hhmma" : "hh:mm a",
        "Invite" : "Invite",
        "Last Name" : "Last Name",
        "male" : "male",
        "Match" : "Match",
        "match" : "match",
        "Middle Name" : "Middle Name",
        "No free time all the day" : "No free time all the day",
        "None-Work" : "None-Work",
        "not going" : "not going",
        "OK" : "OK",
        "Others" : "Others",
        "Out of Town" : "Out of Town",
        "Owner" : "Owner",
        "Personal" : "Personal",
        "personal event need not to invite" : "personal event need not to invite",
        "Phone" : "Phone",
        "private" : "private",
        "Public" : "Public",
        "public" : "public",
        "Pull down to refresh" : "Pull down to refresh",
        "Save" : "Save",
        "Save and Exit without inviting anyone ?" : "Save and Exit without inviting anyone ?",
        "save failed" : "save failed",
        "seconds for new code" : "seconds for new code",
        "Show Calendar" : "’s Plan",
        "Show responses" : "Show responses",
        "Start" : "Start",
        "Start Time" : "Start Time",
        "start time earlier than friend's free time" : "start time earlier than friend's free time",
        "start time can not be later than end time" : "start time can not be later than end time",
        "Time Sensibility" : "Time Sensibility",
        "Title" : "Title",
        "to" : "to",
        "unknown" : "unknown",
        "unread" : "unread",
        "USA" : "USA",
        "User Name" : "User Name",
        "Work" : "Work",
        "sun" : "SUN",
        "mon" : "MON",
        "tue" : "TUE",
        "wed" : "WED",
        "thu" : "THU",
        "fri" : "FRI",
        "sat" : "SAT",
        
        "Sunday":"Sunday",
        "Monday":"Monday",
        "Tuesday":"Tuesday",
        "Wednesday":"Wednesday",
        "Thursday":"Thursday",
        "Friday":"Friday",
        "Saturday":"Saturday",
        "Call allowed" : "Call allowed",
        "Do not disturb" : "Do not disturb",
        "Text allowed" : "Text allowed"
    ]
    
    static let enOtherWords : [String : String] = [
        //event type
        "Call allowed" : "Call allowed",
        "Do not disturb" : "Do not disturb",
        "free" : "free",
        "Free" : "Free",
        "Text allowed" : "Text allowed",
        //calendar type
        "private" : "personal",
        "personal" : "private",
        "public" : "public",
    ]
    
    static let chnWords : [String : String] = [
        "Tell your real friends" : "Zhen伙伴，零距离",
        "Change profile" : "修改简介",
        "Desc" : "详细信息",
        "Avatar" : "头像",
        "avatar bigger than 2M" : "头像文件大于2兆",
        "avatar not found" : "头像未找到",
        "avatar transfering，please wait" : "头像文件处理中，请稍候",
        "avatar uploading failed" : "头像上传失败",
        "Back" : "返回",
        "Calendar" : "日程",
        "CalendarTitle" : "yyyy年MM月",
        "Calendar Type" : "日程类型",
        "Canada" : "加拿大",
        "Cancel" : "放弃",
        "China" : "中国",
        "City" : "城市",
        "code sent" : "验证码已发送",
        "Country" : "国家",
        "Country Code" : "国家/地区",
        "Date" : "日期",
        "Delete" : "删除",
        "delete failed" : "删除失败",
        "Detail" : "事件细节",
        "DoB" : "出生日期",
        "Done" : "完成",
        "End" : "结束",
        "End Time" : "结束时间",
        "end time later than friend's free time" : "结束时间不能超出朋友的空闲时间段",
        "email" : "电子邮箱",
        "Event Type" : "事件类型",
        "Exit without inviting friend" : "退出但未邀请好友",
        "Exit without saving ?" : "不保存直接退出 ?",
        "female" : "女",
        "First Name" : "名字",
        "Free" : "空闲时间",
        "free" : "空闲时间",
        "Gender" : "性别",
        "get data failed" : "读取数据失败",
        "get code" : "获取验证码",
        "get code failed" : "获取验证码失败",
        "get new code" : "重新获取验证码",
        "get phone code" : "获取修改手机号的验证码",
        "get email code" : "获取修改电子邮箱的验证码",
        "going" : "确定参加",
        "HHmm" : "HH:mm",
        "hhmma" : "hh:mm a",
        "Invite" : "邀请",
        "Last Name" : "姓氏",
        "male" : "男",
        "Match" : "匹配时间",
        "match" : "匹配时间",
        "Middle Name" : "中间名字",
        "No free time all the day" : "全天无空闲时间",
        "None-Work" : "非工作",
        "not going" : "不参加",
        "OK" : "好",
        "Others" : "其他国家",
        "Out of Town" : "出差",
        "Owner" : "发起人",
        "Personal" : "私人事件",
        "personal event need not to invite" : "私人事件不需要邀请朋友参加",
        "private" : "私人事件",
        "Public" : "公共事件",
        "public" : "公共事件",
        "Phone" : "电话号码",
        "Pull down to refresh" : "下拉刷新",
        "Save" : "保存",
        "Save and Exit without inviting anyone ?" : "不邀请任何人直接存盘退出 ?",
        "save failed" : "数据保存失败",
        "seconds for new code" : "秒后重新获取",
        "Show Calendar" : "的计划",
        "Show responses" : "查看朋友的答复",
        "Start" : "开始",
        "Start Time" : "开始时间",
        "start time can not be earlier than slot start time" : "开始时间不能超出朋友的空闲时间段",
        "start time can not be later than end time" : "开始时间不能晚于结束时间",
        "Time Sensibility" : "时间状态",
        "Title" : "事件标题",
        "to" : "至",
        "unknown" : "未知",
        "unread" : "未读",
        "USA" : "美国",
        "User Name" : "用户名称",
        "Work" : "工作",
        "sun" : "日",
        "mon" : "一",
        "tue" : "二",
        "wed" : "三",
        "thu" : "四",
        "fri" : "五",
        "sat" : "六",
        "Sunday":"星期日",
        "Monday":"星期一",
        "Tuesday":"星期二",
        "Wednesday":"星期三",
        "Thursday":"星期四",
        "Friday":"星期五",
        "Saturday":"星期六",
        
        "Call allowed":"允许来电",
        "Do not disturb":"免打扰" ,
        "Text allowed":"允许短信"

   ]
    
    static let chnOtherWords : [String : String] = [
        //event type
        "Call allowed" : "允许来电",
        "Do not disturb" : "免打扰",
        "Free" : "无限制",
//        "free" : "无限制",
        "Text allowed" : "允许短信",
        //calendar type
        "private" : "个人日程",
        "public" : "社交日程",
    ]

    static let chnToEnWords : [String : String] = [
        "加拿大" : "Canada",
        "中国" : "China",
        "女" : "female",
        "空闲时间" : "Free",
        "确定参加" : "going",
        "男" : "male",
        "非工作" : "None-Work",
        "不参加" : "not going",
        "其他国家" : "Others",
        "出差" :  "Out of Town",
        "私人事件" : "private",
        "公共事件" : "public",
        "未知" : "unknown",
        "未读" : "unread",
        "美国" : "USA",
        "工作" : "Work",
        ]
    
    static let chnToEnOtherWords : [String : String] = [
        //timesensibility type
        "允许来电" : "Call allowed",
        "免打扰" : "Do not disturb",
        "无限制" : "Free",
        "允许短信" : "Text allowed",
        //calendar type
        "个人日程" : "private",
        "社交日程" : "public",
        ]
    
    static let keyWords : [String : [String : String]] = ["en" : enWords,"chn" : chnWords]
    
    static let keyOtherWords : [String : [String : String]] = ["en" : enOtherWords,"chn" : chnOtherWords]
    
    //根据语言及关键字返回翻译后的词条
    public static func getWord(keyWord : String)->String {
        if keyWord.isEmpty {
            return ""
        }
        var word = EnStatic.keyWords[languegeUsing()]![keyWord]
        if word == nil {
            word = keyWord
        }
        return word!
    }
    
    //根据语言及关键字返回翻译后的词条(特殊部分)
    public static func getOtherWord(keyWord : String)->String {
        if keyWord.isEmpty {
            return ""
        }
        var word = EnStatic.keyOtherWords[languegeUsing()]![keyWord]
        if word == nil {
            word = keyWord
        }
        return word!
    }
    
    //将中文转化为英文
    public static func chnToEnWord(keyWord : String)->String {
        if keyWord.isEmpty {
            return ""
        }
        var word = keyWord
        if languegeUsing().compare("chn").rawValue == 0 {
            word = EnStatic.chnToEnWords[keyWord]!
        }
        return word
    }
    
    //将中文转化为英文(特殊部分)
    public static func chnToEnOtherWord(keyWord : String)->String {
        if keyWord.isEmpty {
            return ""
        }
        var word = keyWord
        if languegeUsing().compare("chn").rawValue == 0 {
            word = EnStatic.chnToEnOtherWords[keyWord]!
        }
        return word
    }
    
    //返回手机正在使用的语言：只有简体中文("zh-Hans-CN")时为"chn"，其余情况皆为"en"
    public static func languegeUsing()->String {
        //获得手机正在使用的语言
        var keyLanguage = "en"
        let languageArr = UserDefaults.standard.object(forKey: "AppleLanguages") as! [String]
        var languageNow = "en"
        //zh-Hans-US or zh-Hans-CN. Traditional Chinese is zh-Hant
        if languageArr.count > 0 {
            languageNow = languageArr[0]
            if languageNow.count >= 7 {
//                languageNow = languageNow.subString(start: 0, length: 7)
//                if languageNow.compare("zh-Hans").rawValue == 0 {
//                    keyLanguage = "chn"
//                }
            }
        }
        return keyLanguage
    }
    
}
